package com.isunland.managesystem.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BasePagerActivity;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.BaseParams;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.LocaleWorkQueryCount;
import com.isunland.managesystem.entity.PayAndBackParams;
import com.isunland.managesystem.utils.MyDateUtil;
import com.isunland.managesystem.utils.MyStringUtil;
import java.util.Date;
import java.util.UUID;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2016/12/12 19:36
 */

public class LocaleWorkQueryCountPagerActivity extends BasePagerActivity {
  private static final String EXTRA_TASK =
      "com.isunland.intelligentFarmbyWJ.ui.OperationTaskPagerActivity.EXTRA_TASK";
  private String mId;
  private LocaleWorkQueryCount mItem;

  public static void newInstance(Fragment fragment, Activity context,
      LocaleWorkQueryCount operationTask, int requestCode) {
    if (fragment == null || context == null) return;
    Intent i = new Intent(context, LocaleWorkQueryCountPagerActivity.class);
    i.putExtra(EXTRA_TASK, operationTask);
    fragment.startActivityForResult(i, requestCode);
  }

  @Override protected void onCreate(Bundle arg0) {
    mItem = (LocaleWorkQueryCount) getIntent().getSerializableExtra(EXTRA_TASK);
    if (mItem != null) mId = mItem.getId();
    super.onCreate(arg0);
  }

  @Override protected Fragment createFragmentOne() {
    return LocaleWorkQueryCountDetailFragment.newInstance(mItem);
  }

  @Override protected Fragment createFragmentTwo() {
    PayAndBackParams params = new PayAndBackParams();
    params.setId(UUID.randomUUID().toString());
    params.setMainId(mId);
    params.setPayMuch(String.valueOf(0));
    params.setEditable(true);
    params.setMoneyType(PayAndBackParams.MONEY_TYPE_DEPOSIT_FEE);
    //noinspection deprecation
    params.setBookOrderNo(
        mItem != null ? MyStringUtil.connect(mItem.getJoinStaffName(), getString(R.string.hyphen),
            MyDateUtil.parseDateToString(MyDateUtil.parseStringToDate(mItem.getWorkstartdate())))
            : "");
    params.setOrderType(PayAndBackParams.ORDER_TYPE_LOCALE_WORK);
    return PayAndBackFragment.newInstance(params, new PayAndBackFragment());
  }

  @Override public Fragment createFragmentThree() {
    String equipId = mItem.getDeviceNo();
    String areaid = mItem.getAreaid();
    Date start = MyDateUtil.stringToDate(mItem.getWorkstartdate(), MyDateUtil.TYPE_ALL);
    Date stop = MyDateUtil.stringToDate(mItem.getWorkenddate(), MyDateUtil.TYPE_ALL);
    //Date stop= MyDateUtil.stringToDate("2016-12-23 00:00:00",MyDateUtil.TYPE_ALL);

    String url = getPathUrl(equipId, areaid, start, stop);
    BaseParams params = new BaseParams();
    params.setRemark(url);
    return LocaleWorkQueryCountPathFragment.newInstance(params,
        new LocaleWorkQueryCountPathFragment());
  }

  @Override protected int[] createTitle() {
    return new int[] { R.string.taskDetail, R.string.settlementInfo, R.string.taskPath };
  }

  @SuppressWarnings("deprecation")
  public String getPathUrl(String equipmentId, String areaId, Date startDate, Date endTime) {

    return MyStringUtil.connect(ApiConst.getAbsoluteUrl(ApiConst.URL_GAODE_MAP), "?equipmentid=",
        equipmentId, "&landIds=", areaId, "&begintime=",
        MyDateUtil.parseTimeToString(startDate, MyDateUtil.TYPE_MINITE), "&endtime=",
        MyDateUtil.parseTimeToString(endTime, MyDateUtil.TYPE_MINITE), "&memberCode=",
        CurrentUser.newInstance(this).getMemberCode(), "&type=back");
  }
}
